<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者，助力商协会发展 
// +----------------------------------------------------------------------
// | Copyright (c) 2017～2024  www.wdsxh.cn    All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn>   www.maiwd.cn
// +----------------------------------------------------------------------
/**
 * Class Area
 * Desc  地区控制器
 * Create on 2024/7/24 14:14
 * Create by wangyafang
 */

namespace app\api\controller\wddj;


use app\common\controller\Api;

class Area extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    protected $model = null;
    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\api\model\wddj\Area();
    }

    /**
     * Desc  省直辖市列表
     * Create on 2024/7/24 14:17
     * Create by wangyafang
     */
    public function province_lists()
    {
        if(!$this->request->isGet()) {
            $this->error('请求类型错误');
        }
        $openAreaArray = array();

        $where['pid'] = array('eq',0);
        $where['level'] = array('eq',1);
        $list = $this->model
            ->where($where)
            ->field('first')
            ->group('first')
            ->select();
        foreach ($list as $k=>&$v) {
            $data = $this->model->where('first',$v['first'])->where($where)->field('id,name shortname,lng,lat')->select();
            if (!empty($openAreaArray)) {
               foreach ($data as $kk=>$vv) {
                   if (!in_array($vv['shortname'],$openAreaArray)) {
                       unset($data[$kk]);
                   }
               }
               if (empty($data)) {
                   unset($list[$k]);
               } else {
                   $data = array_values($data);
               }
            }
            $v['data'] = $data;
            unset($data);
        }
        $this->success('请求成功',$list);
    }

    /**
     * Desc  市列表
     * Create on 2024/7/24 14:32
     * Create by wangyafang
     */
    public function city_lists()
    {
        if(!$this->request->isGet()) {
            $this->error('请求类型错误');
        }
        $pid = $this->request->get('pid');
        $where['pid'] = array('eq',$pid);
        $where['level'] = array('eq',2);
        $list = $this->model
            ->where($where)
            ->field('id,name,lng,lat')
            ->select();
        $this->success('请求成功',$list);
    }
}



 